require("../../@babel/runtime/helpers/Arrayincludes");

var t = getApp();

Page({
    data: {
        page_id: "",
        is_store: !1,
        store_id: "",
        clientWidth: "375",
        page_name: "",
        showPage: !0,
        btnFlag: !1,
        fullShow: !1,
        popShow: !1,
        advertising: {},
        full_screen: {},
        top_info: {},
        bottom_info: {},
        components: [],
        mailInfo: {},
        foot_type: "",
        current_page: 1,
        total_page: 0,
        decorate_isLoadMore: !0,
        isWatch: !0,
        bottomShowBol: !1,
        bottomShowBolIndex: 0,
        lotteryShareId: "",
        pageScrollTopV: 0,

    },
    onLoad: function(a) {
        if (a.page_id && this.setData({
            page_id: a.page_id
        }), a.store_id && this.setData({
            is_store: !0,
            store_id: a.store_id
        }), a.scene) {
            var e = decodeURIComponent(a.scene);
            if (e) {
                var o = [];
                o = e.split(",");
                for (var i = 0; i < o.length; i++) {
                    var n;
                    "mid" == (n = o[i].split("="))[0] && t._setMid(n[1]), "page_id" == n[0] && this.setData({
                        page_id: n[1]
                    }), "store_id" == n[0] && this.setData({
                        store_id: n[1]
                    });
                }
            }
        }
        a.mid && t._setMid(a.mid), 1 == a.lt && this.setData({
            lotteryShareId: a.mid
        }), this.getNewDesinger();
    },
    onReady: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        });
    },
    onShow: function() {
      
    },
    getNewDesinger: function() {
        var a = this, e = this;
        this.setData({
            showPage: !1
        });
        var o = {
            page_id: this.data.page_id
        }, i = t.getNetAddresss("home-page.index");
        this.data.store_id && (i = t.getNetAddresss("plugin.store-cashier.frontend.store.get-store-info.get-the-provider"), 
        o = {
            page_id: this.data.page_id,
            store_id: this.data.store_id
        }), t._getNetWork({
            url: i,
            data: o,
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    var i, n;
                    if (a.data.is_store) return a.setData({
                        showPage: !0,
                        components: o.data.store_decorate.datas,
                        page_name: (null === (i = o.data.store_decorate) || void 0 === i || null === (n = i.page_info) || void 0 === n ? void 0 : n.page_title) || "商家",
                        foot_type: o.data.store_decorate.foot_type
                    }), -1 == o.data.store_decorate.foot_type ? a.setData({
                        bottom_info: {}
                    }) : 1 == o.data.store_decorate.foot_type ? o.data.store_decorate.foot_id && o.data.store_decorate.foot_id.page_info ? a.setData({
                        bottom_info: JSON.parse(o.data.store_decorate.foot_id.page_info)
                    }) : a.setData({
                        bottom_info: {}
                    }) : 2 == o.data.store_decorate.foot_type && (!o.data.store_decorate.foot_id || o.data.store_decorate.foot_id instanceof Array ? a.setData({
                        bottom_info: {}
                    }) : a.setData({
                        bottom_info: JSON.parse(o.data.store_decorate.foot_id.page_info)
                    })), a.data.page_name && wx.setNavigationBarTitle({
                        title: a.data.page_name
                    }), void a.setPageTotal(o.data.store_decorate.page);
                    if (o.data.item) {
                        var s;
                        a.setData({
                            showPage: !0
                        });
                        var d = wx.getStorageSync("yz_basic_info");
                        if (d && (d = d.home.mailInfo), a.setData({
                            components: o.data.item.datas,
                            page_name: null === (s = o.data.item.page_info) || void 0 === s ? void 0 : s.page_title,
                            mailInfo: d || "",
                            foot_type: o.data.item.foot_type,
                            decorate_isLoadMore: !0
                        }), o.data.item.page && a.setPageTotal(o.data.item.page), o.data.item.page_info && (e.setData({
                            advertising: o.data.item.page_info.advertising_id,
                            full_screen: o.data.item.page_info.full_screen_id
                        }), e.data.advertising.id && e.data.advertising.datas && (e.data.advertising.datas = JSON.parse(e.data.advertising.datas), 
                        e.setData({
                            advertising: e.data.advertising
                        }))), o.data.item.top && o.data.item.top.id && a.setData({
                            top_info: JSON.parse(o.data.item.top.page_info)
                        }), -1 == o.data.item.foot_type ? a.setData({
                            bottom_info: {}
                        }) : 1 == o.data.item.foot_type ? o.data.item.foot && o.data.item.foot.page_info ? a.setData({
                            bottom_info: JSON.parse(o.data.item.foot.page_info)
                        }) : a.setData({
                            bottom_info: {}
                        }) : 2 == o.data.item.foot_type && (!o.data.item.foot || o.data.item.foot instanceof Array ? a.setData({
                            bottom_info: {}
                        }) : a.setData({
                            bottom_info: JSON.parse(o.data.item.foot.page_info)
                        })), a.data.full_screen && a.data.full_screen.id) {
                            var r = wx.getStorageSync("page_idFull_screens");
                            r || (r = []), r.includes(a.data.page_id) || (r.push(a.data.page_id), wx.setStorageSync("page_idFull_screens", r), 
                            a.setData({
                                fullShow: !0
                            }), a.countDown(a.data.full_screen.show_time));
                        }
                        if (a.data.advertising && a.data.advertising.id) {
                            var _ = wx.getStorageSync("page_idAdvertisings");
                            _ || (_ = []), _.includes(a.data.page_id) || (_.push(a.data.page_id), wx.setStorageSync("page_idAdvertisings", _), 
                            a.setData({
                                popShow: !0
                            }));
                        }
                        o.data.item.page_info && o.data.item.page_info.preview_color && wx.setNavigationBarColor({
                            backgroundColor: o.data.item.page_info.preview_color,
                            frontColor: 1 == o.data.item.page_info.font_color ? "#ffffff" : "#000000",
                            animation: {
                                duration: 400,
                                timingFunc: "easeIn"
                            }
                        }), e.setData({
                            isWatch: 0 != o.data.item.pageinfo.params.allowauth
                        }), !e.data.isWatch && o.data.item.page_info && o.data.item.page_info.member_level_url && o.data.item.page_info.member_level_url.link && (e.timer = setTimeout(function() {
                            wx.redirectTo({
                                url: o.data.item.page_info.member_level_url.link
                            });
                        }, 3e3)), console.log("会员是否可浏览装修页", e.data.isWatch), a.data.page_name ? wx.setNavigationBarTitle({
                            title: a.data.page_name
                        }) : wx.setNavigationBarTitle({
                            title: "默认标题"
                        });
                    }
                } else wx.showToast({
                    title: o.msg,
                    icon: "none"
                }), console.log(o.msg);
            }
        });

      
    },
    setPageTotal: function(t) {
        t && this.setData({
            total_page: t.total_page,
            current_page: t.current_page,
            bottomShowBolIndex: t.count - 1
        });
    },
    getMoreDecorate: function() {
        var a = this;
        if (a.setData({
            decorate_isLoadMore: !1
        }), a.data.current_page < a.data.total_page) {
            a.setData({
                current_page: a.data.current_page + 1
            });
            var e = t.getNetAddresss("plugin.decorate.frotend.decorate-api.get-page");
            t._postNetWork({
                url: e,
                data: {
                    decorate_page: this.data.current_page,
                    decorate_id: this.data.page_id
                },
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? a.setData({
                        decorate_isLoadMore: !0,
                        components: a.data.components.concat(e.data.datas)
                    }) : (a.setData({
                        decorate_isLoadMore: !1,
                        current_page: a.data.current_page - 1
                    }), console.log(e.msg));
                }
            });
        }
    },
    turnFullTo: function() {
        var t = this.data.full_screen.minapp_link;
        try {
            wx.navigateTo({
                url: t
            });
        } catch (t) {
            wx.showToast({
                title: "链接设置错误",
                icon: "none",
                duration: 2e3
            });
        }
    },
    turnTo: function() {
        var t = this.data.advertising;
        if (2 == t.is_minapp) if (t.minapp_sid) if (t.minapp_link2) try {
            wx.navigateToMiniProgram({
                appId: t.minapp_sid,
                path: t.minapp_link2,
                extraData: {},
                envVersion: "release",
                success: function(t) {},
                fail: function(t) {
                    wx.showToast({
                        title: "小程序跳转失败",
                        icon: "none",
                        duration: 2e3
                    });
                }
            });
        } catch (t) {
            wx.showToast({
                title: "小程序跳转失败",
                icon: "none",
                duration: 2e3
            });
        } else wx.showToast({
            title: "请设置跳转小程序后的跳转链接",
            icon: "none",
            duration: 2e3
        }); else wx.showToast({
            title: "请设置小程序所需跳转appId",
            icon: "none",
            duration: 2e3
        }); else {
            var a = t.minapp_link;
            try {
                wx.navigateTo({
                    url: a
                });
            } catch (t) {
                wx.showToast({
                    title: "链接设置错误",
                    icon: "none",
                    duration: 2e3
                });
            }
        }
    },
    closePop: function() {
        this.setData({
            popShow: !1
        });
    },
    closeFull: function() {
        this.setData({
            fullShow: !1
        });
    },
    countDown: function(t) {
        var a = this, e = t;
        this.setData({
            "full_screen.show_time": e
        }), e--;
        var o = setTimeout(function() {
            if (e <= 0) return a.setData({
                fullShow: !1
            }), void clearInterval(o);
            a.countDown(e);
        }, 1e3);
    },
    onHide: function() {
      console.log('离开页面onHide')
      wx.setStorageSync('isMoneyUnitNiu', false)
    },
    onUnload: function() {
        clearTimeout(this.timer);
        console.log('离开页面onUnload')
        wx.setStorageSync('isMoneyUnitNiu', false)
    },
    onPullDownRefresh: function() {},
    onPageScroll: function(t) {
        this.setData({
            pageScrollTopV: t.scrollTop
        }), t.scrollTop > 80 ? this.data.btnFlag || this.setData({
            btnFlag: !0
        }) : this.data.btnFlag && this.setData({
            btnFlag: !1
        }), this.data.bottomShowBol && this.setData({
            bottomShowBol: !1
        });
    },
    onReachBottom: function() {
        this.setData({
            bottomShowBol: !0
        }), this.data.decorate_isLoadMore && this.getMoreDecorate();
    },
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "/packageG/newDiy/newDiy?page_id=".concat(this.data.page_id);
        return this.data.is_store && (a = a + "&store_id" + this.data.store_id), t && (a = a + "&mid" + t), 
        this.data.components.forEach(function(t) {
            "U_lottery" == t.component_key && (a += "&lt=1");
        }), {
            title: this.data.page_name ? this.data.page_name : "",
            path: a
        };
    },
    onShareAppMessage: function(a) {
        var e = this, o = wx.getStorageSync("yz_uid"), i = "";
        o && (i = o);
        var n = {
            title: this.data.page_name ? this.data.page_name : "",
            path: "/packageG/newDiy/newDiy?page_id=".concat(this.data.page_id, "&mid=").concat(i)
        };
        if (a && "button" == a.from && "shareTag" == a.target.dataset.tag && "1" == a.target.dataset.item) {
            var s = "/packageB/member/group/GroupDetail/GroupDetail?id=" + a.target.dataset.info.id + "&mid=" + i, d = a.target.dataset.title;
            return a.target.dataset.store && (s = "/packageB/member/group/GroupDetail/GroupDetail?id=" + a.target.dataset.info.id + "store=" + a.target.dataset.store + "&mid=" + i), 
            1 == t.globalData.store_alone_temp && that.globalData.STORE_ID && (s = "".concat(s, "&store_alone_id=").concat(t.globalData.STORE_ID)), 
            {
                path: s,
                title: d
            };
        }
        return this.data.store_id ? {
            title: this.data.page_name ? this.data.page_name : "",
            path: "/packageG/newDiy/newDiy?page_id=".concat(this.data.page_id, "&mid=").concat(i, "&store_id=").concat(this.data.store_id)
        } : (this.data.components.forEach(function(t) {
            "U_lottery" == t.component_key && (n.path = "/packageG/newDiy/newDiy?page_id=".concat(e.data.page_id, "&mid=").concat(i, "&lt=1"));
        }), n);
    }
});